trigger UpdateConsumerEducationPlans on ConsumerEducation__c (before update) {
recordtype rt=[select id from recordtype where sobjecttype=:'ConsumerEducation__c' and name=:'全国消费者教育'];
  if (Trigger.New[0].RecordTypeId==rt.id){
    Map<Id,ConsumerEducation__c> planMap=new Map<Id,ConsumerEducation__c>();
    List<ConsumerEducation__c> ceMap=new List<ConsumerEducation__c>();
    
    for(Integer i=0;i<Trigger.new.size();i++)
    {
        Date ActiveD=Trigger.old[i].Date__c;
        Date todayD=System.today();
 //       Integer count=actived-todayd;             ///todayD.daysBetween(ActiveD);
        if(true)    //(count>1)//活动开始时间大于1可以修改
         {
            if(Trigger.old[i].Name!=Trigger.new[i].Name
               || Trigger.old[i].venue__c!=Trigger.new[i].venue__c
               || Trigger.old[i].HCP_NEW__c != Trigger.new[i].HCP_NEW__c
               || Trigger.old[i].Date__c!= Trigger.new[i].Date__c
               || Trigger.old[i].ifnonhospital__c!= Trigger.new[i].ifnonhospital__c
               || Trigger.old[i].messaging__c!=Trigger.new[i].messaging__c
               || Trigger.old[i].organizer__c!=Trigger.new[i].organizer__c
               || Trigger.old[i].OwnerId!=Trigger.new[i].OwnerId)
           {
                planMap.put(Trigger.old[i].Id,Trigger.new[i]);
           }
        }
        else
        {
            Trigger.new[i].Date__c.addError('您不能在活动举行前一天对活动信息作出修改。');
        }
    }
    
 /*   for(ConsumerEducation__c ed:[Select venue__c, organizer__c, messaging__c, ifotherorganizer__c, 
                                        ifnonhospital__c, OwnerId,Name,Id,Hospital__c,HCP_NEW__c,Date__c,ConsumerEducationRecord__c
                                        From ConsumerEducation__c where ConsumerEducationRecord__c in : planMap.keySet()])
    {
        ConsumerEducation__c plan=planMap.get(ed.ConsumerEducationRecord__c);
        ed.Name=plan.Name;
        ed.venue__c=plan.venue__c;
        ed.HCP_NEW__c=plan.HCP_NEW__c;
        ed.Date__c=plan.Date__c;
        ed.ifnonhospital__c=plan.ifnonhospital__c;
        ed.ifotherorganizer__c=plan.ifotherorganizer__c;
        ed.messaging__c=plan.messaging__c;
        ed.organizer__c=plan.organizer__c;
        
        ceMap.add(ed);
    }
    update ceMap;*/
    }
}